/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package encaps.utils;

import encaps.action.Action;
import encaps.action.ActionExecutionException;
import encaps.security.DataAccessException;
import encaps.security.SecuritySystem;


public class ActionExecutor {

    private static SecuritySystem securitySystem = new SecuritySystem();

    public static String executeAction(String userRole, Action action) throws ActionExecutionException {
        try {
            if (securitySystem.isActionAllowed(userRole, action) && action != null) {
                return action.execute();
            } else {
                return "Cannot perform action";
            }
        } catch (DataAccessException ex) {
            throw new ActionExecutionException(ex);
        } catch (ActionExecutionException ex) {
            throw new ActionExecutionException(ex);
        }
    }
}
